<script setup name="BseWorkProceedDetail">

import { ref } from 'vue';
import { useRouter } from 'vue-router';

import { ElIcon, ElMessage } from "element-plus";
import { Close } from "@element-plus/icons-vue";

import service from '@/utils/request';

const router = useRouter();
const routerQuery = router.currentRoute.value.query;

//基础工作考核信息
const baseWorkData = ref({
    //基本信息
    username: "",
    jobId: "",
    baseWorkName: "",
    baseWorkState: "",
    //基本要求
    basicRequirementImg: [],
    basicRequirementWord: [],
    basicRequirementScore: "0",
    //学生思想引领
    studentThoughtImg: [],
    studentThoughtWord: [],
    studentThoughtScore: "0",
    //学生学业规划
    academicPlanningImg: [],
    academicPlanningWord: [],
    academicPlanningScore: "0",
    //学生职业规划
    careerPlanningImg: [],
    careerPlanningWord: [],
    careerPlanningScore: "0",
    //学生科研成果
    researchAchievementImg: [],
    researchAchievementWord: [],
    researchAchievementScore: "0",
});

//预览图片的内容
const previewImgData = ref('');
const isShowPreviewImg = ref(false);

//获取基础工作考核信息
const fixedBaseWorkData = (data) => {
    if(!data) return {};
    return {
        //基本信息
        username: data.username,
        jobId: data.jobId,
        baseWorkName: data.baseWorkName,
        baseWorkState: data.baseWorkState,
        //基本要求
        basicRequirementImg: Array.isArray(data.basicRequirementUrl) ? data.basicRequirementUrl.filter((item) => {
            if(!item.includes(".doc") && !item.includes(".docx")) return item;
        }) : [],
        basicRequirementWord: Array.isArray(data.basicRequirementUrl) ? data.basicRequirementUrl.filter((item) => {
            if(item.includes(".doc") || item.includes(".docx")) return item;
        }) : [],
        basicRequirementScore: data.basicRequirementScore,
        //学生思想引领
        studentThoughtImg: Array.isArray(data.studentThoughtUrl) ? data.studentThoughtUrl.filter((item) => {
            if(!item.includes(".doc") && !item.includes(".docx")) return item;
        }) : [],
        studentThoughtWord: Array.isArray(data.studentThoughtUrl) ? data.studentThoughtUrl.filter((item) => {
            if(item.includes(".doc") || item.includes(".docx")) return item;
        }) : [],
        studentThoughtScore: data.studentThoughtScore,
        //学生学业规划
        academicPlanningImg: Array.isArray(data.academicPlanningUrl) ? data.academicPlanningUrl.filter((item) => {
            if(!item.includes(".doc") && !item.includes(".docx")) return item;
        }) : [],
        academicPlanningWord: Array.isArray(data.academicPlanningUrl) ? data.academicPlanningUrl.filter((item) => {
            if(item.includes(".doc") || item.includes(".docx")) return item;
        }) : [],
        academicPlanningScore: data.academicPlanningScore,
        //学生职业规划
        careerPlanningImg: Array.isArray(data.careerPlanningUrl) ? data.careerPlanningUrl.filter((item) => {
            if(!item.includes(".doc") && !item.includes(".docx")) return item;
        }) : [],
        careerPlanningWord: Array.isArray(data.careerPlanningUrl) ? data.careerPlanningUrl.filter((item) => {
            if(item.includes(".doc") || item.includes(".docx")) return item;
        }) : [],
        careerPlanningScore: data.careerPlanningScore,
        //学生科研成果
        researchAchievementImg: Array.isArray(data.researchAchievementUrl) ? data.researchAchievementUrl.filter((item) => {
            if(!item.includes(".doc") && !item.includes(".docx")) return item;
        }) : [],
        researchAchievementWord: Array.isArray(data.researchAchievementUrl) ? data.researchAchievementUrl.filter((item) => {
            if(item.includes(".doc") || item.includes(".docx")) return item;
        }) : [],
        researchAchievementScore: data.researchAchievementScore,
    }
}
const getBaseWorkData = () => {
    service({
        method: "post",
        url: "/superadmin/score/basework",
        headers: {
            Authorization: 'Bearer ' + localStorage.getItem('token'),   
        },
        params: {
            baseWorkId: routerQuery.workId,
        }
    }).then((res) => {
        //console.log(res);
        baseWorkData.value = fixedBaseWorkData(res.data || {});
    }).catch((error) => {
        ElMessage({
            message: '获取数据失败',
            type: 'error',
        });
        baseWorkData.value = {};
    })
}
getBaseWorkData();

//点击下载word文档
const downloadWord = (url) => {
    const elink = document.createElement('a');
    document.body.appendChild(elink);    
    url.forEach((item) => {
        elink.href = item;
        elink.click();
    })
    document.body.removeChild(elink);
}
//点击预览图片
const previewImgClick = (url) => {
    previewImgData.value = url;
    isShowPreviewImg.value = true;
}

</script>

<template>
    <div class="imgPreview" v-show="isShowPreviewImg" @click="isShowPreviewImg = false">
        <div class="imgContent">
            <span class="close" @click.stop="isShowPreviewImg = false">
                <el-icon><Close /></el-icon>
            </span>
            <img :src="previewImgData" alt="预览图片">            
        </div>
    </div>
    <div class="bseWorkProceedDetail">
        <div class="header">
            <span @click="router.push('/superAdministrator/scoreOverview')">进行中-考核情况列表</span>
            <span>/</span>
            <span @click="router.push({
                path: '/superAdministrator/scoreOverview/proceed/detail',
                query: routerQuery
            })">导师情况</span>
            <span>/</span>
            <span>导师基础工作情况</span>
        </div>
        <div class="layout">
            <div class="layoutHeader">基础工作详情</div>
            <div class="layoutContent">
                <!-- 基本信息栏 -->
                <div class="baseInfo">
                    <div class="contentHeader">
                        <div class="line"></div>
                        <div>基本信息</div>
                    </div>
                    <div class="content">
                        <div class="item">
                            <span class="label">教师姓名</span>
                            <span class="value">{{ routerQuery.name }}</span>
                        </div>
                        <div class="item">
                            <span class="label">工号</span>
                            <span class="value">{{ routerQuery.jobId }}</span>
                        </div>
                        <div class="item">
                            <span class="label">任务名称</span>
                            <span class="value">{{ routerQuery.taskName }}</span>
                        </div>
                        <div class="item">
                            <span class="label">任务状态</span>
                            <span class="value">{{ routerQuery.taskStatus }}</span>
                        </div>
                    </div>
                </div>
                <!-- 基本要求栏 -->
                <div class="markContent">
                    <div class="contentHeader">
                        <div class="line"></div>
                        <div>基本要求</div>
                    </div>
                    <div class="content">
                        <div class="proveItem">
                            <div class="title">支撑材料</div>
                            <div class="proveItemContent" v-if="baseWorkData.basicRequirementImg.length > 0 || baseWorkData.basicRequirementWord.length > 0">
                                <div class="img" v-if="baseWorkData.basicRequirementImg.length > 0">
                                    <img v-for="(item, index) in baseWorkData.basicRequirementImg" :key="index" :src="item" alt="证明材料" @click="previewImgClick(item)">
                                </div>
                                <div class="download" @click="downloadWord(baseWorkData.basicRequirementWord)" v-if="baseWorkData.basicRequirementWord.length > 0">下载word材料</div>
                            </div>
                            <div class="no-data" v-else>无</div>
                        </div>
                        <div class="scoreItem">
                            <span class="title">分数</span>
                            <span class="scoreValue">{{ baseWorkData.basicRequirementScore || 0 }}</span>
                        </div>
                    </div>
                </div>
                <!-- 学生思想引领 -->
                <div class="markContent">
                    <div class="contentHeader">
                        <div class="line"></div>
                        <div>学生思想引领</div>
                    </div>
                    <div class="content">
                        <div class="proveItem">
                            <div class="title">证明材料</div>
                            <div class="proveItemContent" v-if="baseWorkData.studentThoughtImg.length > 0 || baseWorkData.studentThoughtWord.length > 0">
                                <div class="img" v-if="baseWorkData.studentThoughtImg.length > 0">
                                    <img v-for="(item, index) in baseWorkData.studentThoughtImg" :key="index" :src="item" alt="证明材料" @click="previewImgClick(item)">
                                </div>
                                <div class="download" @click="downloadWord(baseWorkData.studentThoughtWord)" v-if="baseWorkData.studentThoughtWord.length > 0">下载word材料</div>
                            </div>
                            <div class="no-data" v-else>无</div>
                        </div>
                        <div class="scoreItem">
                            <span class="title">分数</span>
                            <span class="scoreValue">{{ baseWorkData.studentThoughtScore || 0 }}</span>
                        </div>
                    </div>
                </div>
                <!-- 学生学业规划 -->
                <div class="markContent">
                    <div class="contentHeader">
                        <div class="line"></div>
                        <div>学生学业规划</div>
                    </div>
                    <div class="content">
                        <div class="proveItem">
                            <div class="title">支撑材料</div>
                            <div class="proveItemContent" v-if="baseWorkData.academicPlanningImg.length > 0 || baseWorkData.academicPlanningWord.length > 0">
                                <div class="img" v-if="baseWorkData.academicPlanningImg.length > 0">
                                    <img v-for="(item, index) in baseWorkData.academicPlanningImg" :key="index" :src="item" alt="证明材料" @click="previewImgClick(item)">
                                </div>
                                <div class="download" @click="downloadWord(baseWorkData.academicPlanningWord)" v-if="baseWorkData.academicPlanningWord.length > 0">下载word材料</div>
                            </div>
                            <div class="no-data" v-else>无</div>
                        </div>
                        <div class="scoreItem">
                            <span class="title">分数</span>
                            <span class="scoreValue">{{ baseWorkData.academicPlanningScore || 0 }}</span>
                        </div>
                    </div>
                </div>
                <!-- 学生职业规划 -->
                <div class="markContent">
                    <div class="contentHeader">
                        <div class="line"></div>
                        <div>学生职业规划</div>
                    </div>
                    <div class="content">
                        <div class="proveItem">
                            <div class="title">支撑材料</div>
                            <div class="proveItemContent" v-if="baseWorkData.careerPlanningImg.length > 0 || baseWorkData.careerPlanningWord.length > 0">
                                <div class="img" v-if="baseWorkData.careerPlanningImg.length > 0">
                                    <img v-for="(item, index) in baseWorkData.careerPlanningImg" :key="index" :src="item" alt="证明材料" @click="previewImgClick(item)">
                                </div>
                                <div class="download" @click="downloadWord(baseWorkData.careerPlanningWord)" v-if="baseWorkData.careerPlanningWord.length > 0">下载word材料</div>
                            </div>
                            <div class="no-data" v-else>无</div>
                        </div>
                        <div class="scoreItem">
                            <span class="title">分数</span>
                            <span class="scoreValue">{{ baseWorkData.careerPlanningScore || 0 }}</span>
                        </div>
                    </div>
                </div>
                <!-- 学生科研成果 -->
                <div class="markContent">
                    <div class="contentHeader">
                        <div class="line"></div>
                        <div>学生科研成果</div>
                    </div>
                    <div class="content">
                        <div class="proveItem">
                            <div class="title">支撑材料</div>
                            <div class="proveItemContent" v-if="baseWorkData.researchAchievementImg.length > 0 || baseWorkData.researchAchievementWord.length > 0">
                                <div class="img" v-if="baseWorkData.researchAchievementImg.length > 0">
                                    <img v-for="(item, index) in baseWorkData.researchAchievementImg" :key="index" :src="item" alt="证明材料" @click="previewImgClick(item)">
                                </div>
                                <div class="download" @click="downloadWord(baseWorkData.researchAchievementWord)" v-if="baseWorkData.researchAchievementWord.length > 0">下载word材料</div>
                            </div>
                            <div class="no-data" v-else>无</div>
                        </div>
                        <div class="scoreItem">
                            <span class="title">分数</span>
                            <span class="scoreValue">{{ baseWorkData.researchAchievementScore || 0 }}</span>
                        </div>
                    </div>
                </div>
                <!-- 分数合计部分 -->
                <div class="totalScore">
                    <div class="contentHeader">
                        <div class="line"></div>
                        <div>分数合计</div>
                    </div>
                    <div class="content">
                        <div class="item scoreItem">
                            <span class="totalScoreValue">{{ routerQuery.sumScore || '未评分' }}</span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<style scoped lang="scss">
// 颜色变量
$primary-color: #4c5fbc;
$border-color: #cacacb;
$text-color: #333;
$text-secondary: #7f7f7f;
$text-placeholder: #afafaf;
$bg-color: #f2f3f5;
$bg-white: #ffffff;
$hover-bg: #e6f7ff;
$shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
$border-radius: 8px;

//预览图片样式优化
.imgPreview {
    width: 100%;
    height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 999;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 0.3s ease;
    
    .imgContent {
        position: relative;
        max-width: 90%;
        max-height: 90%;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
        border-radius: $border-radius;
        overflow: hidden;
        
        img {
            max-width: 100%;
            max-height: 90vh;
            display: block;
            object-fit: contain;
        }
        
        .close {
            position: absolute;
            top: 10px;
            right: 10px;
            cursor: pointer;
            font-size: 24px;
            color: #fff;
            background-color: rgba(0, 0, 0, 0.5);
            width: 32px;
            height: 32px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: all 0.3s ease;
            
            &:hover {
                background-color: rgba(255, 0, 0, 0.7);
                transform: scale(1.1);
            }
        }
    }
}

.bseWorkProceedDetail {
    width: 100%;
    height: 100%;
    color: $text-color;
    
    .header {
        width: 100%;
        height: 60px;
        padding-left: 20px;
        display: flex;
        align-items: center;
        gap: 10px;
        color: $text-secondary;
        border-top: 1px solid $border-color;
        border-bottom: 1px solid $border-color;
        background-color: $bg-white;
        font-size: 16px;
        box-shadow: $shadow;
        
        span {
            cursor: pointer;
            transition: all 0.3s ease;
            
            &:hover {
                color: $primary-color;
                font-weight: 600;
            }
            
            &:nth-child(2),
            &:nth-child(4) {
                cursor: default;
                &:hover {
                    color: $text-secondary;
                    font-weight: normal;
                }
            }
        }
    }
    
    .layout {
        width: 100%;
        height: calc(100% - 60px);
        padding: 0 80px;
        display: flex;
        flex-direction: column;
        align-items: center;
        
        .layoutHeader {
            width: 100%;
            margin-top: 40px;
            margin-bottom: 20px;
            font-size: 24px;
            font-weight: 600;
            color: $text-color;
            text-align: center;
        }
        
        .layoutContent {
            width: 100%;
            height: calc(100% - 80px);
            margin-bottom: 20px;
            overflow-y: auto;
            
            &::-webkit-scrollbar {
                width: 6px;
            }
            
            &::-webkit-scrollbar-track {
                background: $bg-color;
                border-radius: 3px;
            }
            
            &::-webkit-scrollbar-thumb {
                background: $border-color;
                border-radius: 3px;
                
                &:hover {
                    background: darken($border-color, 10%);
                }
            }
            
            // 通用区块样式
            .baseInfo,
            .markContent,
            .totalScore {
                width: 100%;
                margin-top: 30px;
                padding: 25px 20px;
                background-color: $bg-white;
                border-radius: $border-radius;
                box-shadow: $shadow;
                transition: all 0.3s ease;
                
                &:hover {
                    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
                }
                
                .contentHeader {
                    width: 100%;
                    height: 30px;
                    display: flex;
                    align-items: center;
                    gap: 10px;
                    font-size: 18px;
                    font-weight: 600;
                    color: $text-color;
                    margin-bottom: 20px;
                    
                    .line {
                        width: 5px;
                        height: 22px;
                        background-color: $primary-color;
                        border-radius: 2px;
                    }
                }
            }
            
            // 基本信息样式
            .baseInfo {
                .content {
                    width: 100%;
                    display: flex;
                    flex-wrap: wrap;
                    gap: 20px 0;
                    padding: 0 10px;
                    
                    .item {
                        width: 50%;
                        display: flex;
                        align-items: center;
                        gap: 15px;
                        font-size: 16px;
                        
                        .label {
                            min-width: 100px;
                            font-weight: 500;
                            color: $text-secondary;
                        }
                        
                        .value {
                            color: $text-color;
                            font-weight: 500;
                        }
                    }
                }
            }
            
            // 标记内容样式
            .markContent {
                .content {
                    width: 100%;
                    padding: 0 10px;
                    
                    .proveItem {
                        width: 100%;
                        margin-top: 20px;
                        display: flex;
                        gap: 40px;
                        
                        .title {
                            width: 100px;
                            height: 30px;
                            line-height: 30px;
                            text-align: right;
                            white-space: nowrap;
                            font-weight: 500;
                            color: $text-secondary;
                        }
                        
                        .proveItemContent {
                            flex: 1;
                            
                            .img {
                                width: 100%;
                                display: flex;
                                flex-wrap: wrap;
                                gap: 15px;
                                margin-bottom: 15px;
                                
                                img {
                                    width: 120px;
                                    height: 160px;
                                    object-fit: cover;
                                    border-radius: 6px;
                                    cursor: pointer;
                                    transition: all 0.3s ease;
                                    border: 1px solid $border-color;
                                    
                                    &:hover {
                                        transform: scale(1.03);
                                        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
                                    }
                                }
                            }
                            
                            .download {
                                display: inline-flex;
                                align-items: center;
                                justify-content: center;
                                width: 120px;
                                height: 36px;
                                margin-top: 5px;
                                text-align: center;
                                line-height: 36px;
                                background-color: $bg-color;
                                border: 1px solid $border-color;
                                border-radius: 6px;
                                color: $text-secondary;
                                font-size: 14px;
                                cursor: pointer;
                                transition: all 0.3s ease;
                                
                                &:hover {
                                    background-color: $primary-color;
                                    color: #fff;
                                    border-color: $primary-color;
                                    transform: translateY(-1px);
                                }
                            }
                        }
                        
                        .no-data {
                            flex: 1;
                            height: 30px;
                            line-height: 30px;
                            color: $text-placeholder;
                            font-style: italic;
                        }
                    }
                    
                    .scoreItem {
                        width: 100%;
                        margin-top: 25px;
                        display: flex;
                        gap: 40px;
                        align-items: center;
                        
                        .title {
                            width: 100px;
                            height: 30px;
                            line-height: 30px;
                            text-align: right;
                            font-weight: 500;
                            color: $text-secondary;
                        }
                        
                        .scoreValue {
                            font-size: 18px;
                            font-weight: 600;
                            color: $primary-color;
                        }
                    }
                }
            }
            
            // 总分样式
            .totalScore {
                margin-bottom: 30px;
                .content {
                    width: 100%;
                    display: flex;
                    padding: 20px 0;
                    .item {
                        .totalScoreValue {
                            font-size: 20px;
                            font-weight: bold;
                            color: $primary-color;
                            padding: 8px 20px;
                            background-color: $bg-color;
                            border-radius: 10px;
                            min-width: 100px;
                            text-align: center;
                        }
                    }
                }
            }
        }
    }
}

// 响应式设计
@media (max-width: 768px) {
    .bseWorkProceedDetail {
        .layout {
            padding: 0 20px;
            
            .layoutContent {
                .baseInfo {
                    .content {
                        .item {
                            width: 100%;
                            
                            .label {
                                min-width: 80px;
                            }
                        }
                    }
                }
                
                .markContent {
                    .content {
                        .proveItem,
                        .scoreItem {
                            gap: 20px;
                            
                            .title {
                                width: 80px;
                                font-size: 14px;
                            }
                        }
                        
                        .proveItem {
                            flex-direction: column;
                            align-items: flex-start;
                            
                            .title {
                                text-align: left;
                            }
                        }
                    }
                }
                
                .totalScore {
                    .content {
                        .item {
                            flex-direction: column;
                            gap: 15px;
                            
                            .totalScoreValue {
                                font-size: 24px;
                            }
                        }
                    }
                }
            }
        }
    }
}
</style>